package com.lxj.api;

import android.content.Context;

import com.loopj.android.http.RequestParams;
import com.lxj.utils.PublicFunction;

public class ApiConfig {

	public static boolean TESTMODE = false;

	private final static String HOST = "a498002079.xicp.net";
	private final static int PORT = 81;
	private final static String VERSION = "v1";

	private final static String DEVICE_OS_TYPE = "4";
	private final static String CHANNEL_ID = "1";
	private static String DEVICE_IMEI = null;
	private static String DEVICE_MODEL = null;
	private static String DEVICE_OS_VERSION = null;
	private static String VERSION_CODE = null;
	private static String USER_ID = null;
	private static String ACCESS_TOKEN = null;
	private static String SESSION_KEY = null;

	// socket
	public final static int PROTOCAOL_ID = 1;
	public final static String CGI_FILE_NAME = "test.food_file";
	public final static String CGI_PUSH_NAME = "test.food.api.haoyoudou.com";

	public final static String SOCKET_PUSH_HOST = "test.food.api.haoyoudou.com";
	public final static int SOCKET_PUSH_PORT = 6202;

	public final static String SOCKET_FILE_HOST = "27.154.233.162";
	public final static int SOCKET_FILE_PORT = 6200;

	public final static String RESULT_CODE_SUCCESS = "10000";

	public final static String RESULT_CODE_NO_AUTH = "90001";
	public final static String RESULT_CODE_NO_PARAMETERS = "90002";
	public final static String RESULT_CODE_SERVER_FAIL = "99999";

	public final static String RESULT_CODE_PHONE_EXIST = "20001";
	public final static String RESULT_CODE_PHONE_FORMAT_ERROR = "20002";
	public final static String RESULT_CODE_PASSWORD_ERROR = "20003";
	public final static String RESULT_CODE_USERNAME_FORMAT_ERROR = "20004";
	public final static String RESULT_CODE_PHONE_NOT_REGISTER = "20005";
	public final static String RESULT_CODE_VERIFYCODE_ERROR = "20006";

	public final static String RESULT_CODE_FRIEND_REQUEST_ADD_SUCCESS = "30001";
	public final static String RESULT_CODE_FRIEND_REQUEST_NEED_VERIFY = "30002";
	public final static String RESULT_CODE_FRIEND_REQUEST_SEND_VERIFY_SUCCESS = "30003";
	public final static String RESULT_CODE_FRIEND_ALREADY_FRIENDS = "30005";
	public final static String RESULT_CODE_FRIEND_INFO_NOT_EXIST = "30006";
	public final static String RESULT_CODE_FRIEND_EXPIRED = "30007";

	public final static String RESULT_CODE_STORE_ADD_PHONE_EXIST = "40001";

	public final static String RESULT_CODE = "resultcode";
	public final static String RESULT_INFO = "result";
	public final static String RESULT_DATA = "data";

	public final static int AVATAR_LISTITEM_SIZE = 200;
	public final static int AVATAR_LISTITEM_SMALL_SIZE = 50;

	public final static int AVATAR_SIZE = 400;

	public static String getApiHost() {
		return HOST + ":" + PORT + "/" + VERSION + "/index.php";
	}

	public static void initCommonParameters(Context aContext) {
		DEVICE_IMEI = PublicFunction.getPhoneDeviceId(aContext);
		DEVICE_MODEL = PublicFunction.getDeviceModel();
		DEVICE_OS_VERSION = PublicFunction.getOsBuildVersionRelease();
		VERSION_CODE = String.valueOf(PublicFunction.getVersionCode(aContext));
	}

	public static void setUserID(String aUserID) {
		USER_ID = aUserID;
	}

	public static void setToken(String aToken) {
		ACCESS_TOKEN = aToken;
	}

	public static String getPicUrl(String aHost, int aPicID, int aWidth,
			int aHeight) {
		return aHost + aPicID + "/" + aWidth + "/" + aHeight;
	}



	



	public static RequestParams profile(String aName, int aSex, int aBirthday,
			String aAvatarID, int isNeedVerify) {
		RequestParams ret = getCommonParameters();
		ret.add("c", "ApiUser::profile");
		if (aName != null) {
			ret.add("name", aName);
		}

		if (aSex != -1) {
			ret.add("sex", String.valueOf(aSex));
		}

		if (aBirthday != -1) {
			ret.add("birthday", String.valueOf(aBirthday));
		}

		if (aAvatarID != null) {
			ret.add("pic_id", aAvatarID);
		}

		if (isNeedVerify != -1) {
			ret.add("friend_verify", String.valueOf(isNeedVerify));
		}
		return ret;
	}

	public static RequestParams Detail(String aUserID) {
		RequestParams ret = getCommonParameters();
		ret.add("c", "ApiUser::Detail");
		ret.add("user_id", aUserID);
		return ret;
	}
	
	private static RequestParams getCommonParameters()
	{
		RequestParams ret = new RequestParams();
		ret.add("g_device_os", DEVICE_OS_TYPE);
		ret.add("g_imei", DEVICE_IMEI);
		ret.add("g_device_model", DEVICE_MODEL);
		ret.add("g_device_os_version", DEVICE_OS_VERSION);
		ret.add("g_version_code", VERSION_CODE);
		ret.add("g_channel_id", CHANNEL_ID);
		ret.add("g_session_key", SESSION_KEY);
		if(USER_ID != null)
		{
			ret.add("g_userid", USER_ID);
		}
		
		if(ACCESS_TOKEN != null)
		{
			ret.add("g_access_token", ACCESS_TOKEN);
		}
		return ret;
	}

}
